<?php

/**
 * MessagingApi
 * PHP version 8.3.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Selling Partner API for Messaging.
 *
 * With the Messaging API you can build applications that send messages to buyers. You can get a list of message types that are available for an order that you specify, then call an operation that sends a message to the buyer for that order. The Messaging API returns responses that are formed according to the <a href=https://tools.ietf.org/html/draft-kelly-json-hal-08>JSON Hypertext Application Language</a> (HAL) standard.
 *
 * The version of the OpenAPI document: v1
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Api\messaging\v1;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use SpApi\ApiException;
use SpApi\AuthAndAuth\RestrictedDataTokenSigner;
use SpApi\Configuration;
use SpApi\HeaderSelector;
use SpApi\Model\messaging\v1\CreateAmazonMotorsRequest;
use SpApi\Model\messaging\v1\CreateAmazonMotorsResponse;
use SpApi\Model\messaging\v1\CreateConfirmCustomizationDetailsRequest;
use SpApi\Model\messaging\v1\CreateConfirmCustomizationDetailsResponse;
use SpApi\Model\messaging\v1\CreateConfirmDeliveryDetailsRequest;
use SpApi\Model\messaging\v1\CreateConfirmDeliveryDetailsResponse;
use SpApi\Model\messaging\v1\CreateConfirmOrderDetailsRequest;
use SpApi\Model\messaging\v1\CreateConfirmOrderDetailsResponse;
use SpApi\Model\messaging\v1\CreateConfirmServiceDetailsRequest;
use SpApi\Model\messaging\v1\CreateConfirmServiceDetailsResponse;
use SpApi\Model\messaging\v1\CreateDigitalAccessKeyRequest;
use SpApi\Model\messaging\v1\CreateDigitalAccessKeyResponse;
use SpApi\Model\messaging\v1\CreateLegalDisclosureRequest;
use SpApi\Model\messaging\v1\CreateLegalDisclosureResponse;
use SpApi\Model\messaging\v1\CreateUnexpectedProblemRequest;
use SpApi\Model\messaging\v1\CreateUnexpectedProblemResponse;
use SpApi\Model\messaging\v1\CreateWarrantyRequest;
use SpApi\Model\messaging\v1\CreateWarrantyResponse;
use SpApi\Model\messaging\v1\GetAttributesResponse;
use SpApi\Model\messaging\v1\GetMessagingActionsForOrderResponse;
use SpApi\Model\messaging\v1\InvoiceRequest;
use SpApi\Model\messaging\v1\InvoiceResponse;
use SpApi\ObjectSerializer;
use Symfony\Component\RateLimiter\LimiterInterface;
use Symfony\Component\RateLimiter\RateLimiterFactory;
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;

/**
 * MessagingApi Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */
class MessagingApi
{
    public ?LimiterInterface $confirmCustomizationDetailsRateLimiter;
    public ?LimiterInterface $createAmazonMotorsRateLimiter;
    public ?LimiterInterface $createConfirmDeliveryDetailsRateLimiter;
    public ?LimiterInterface $createConfirmOrderDetailsRateLimiter;
    public ?LimiterInterface $createConfirmServiceDetailsRateLimiter;
    public ?LimiterInterface $createDigitalAccessKeyRateLimiter;
    public ?LimiterInterface $createLegalDisclosureRateLimiter;
    public ?LimiterInterface $createUnexpectedProblemRateLimiter;
    public ?LimiterInterface $createWarrantyRateLimiter;
    public ?LimiterInterface $getAttributesRateLimiter;
    public ?LimiterInterface $getMessagingActionsForOrderRateLimiter;
    public ?LimiterInterface $sendInvoiceRateLimiter;
    protected ClientInterface $client;

    protected Configuration $config;

    protected HeaderSelector $headerSelector;

    /**
     * @var int Host index
     */
    protected int $hostIndex;

    private bool $rateLimiterEnabled;
    private InMemoryStorage $rateLimitStorage;

    /**
     * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
     */
    public function __construct(
        Configuration $config,
        ?ClientInterface $client = null,
        ?bool $rateLimiterEnabled = true,
        ?HeaderSelector $selector = null,
        int $hostIndex = 0
    ) {
        $this->config = $config;
        $this->rateLimiterEnabled = $rateLimiterEnabled;

        if ($rateLimiterEnabled) {
            $this->rateLimitStorage = new InMemoryStorage();

            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-confirmCustomizationDetails'), $this->rateLimitStorage);
            $this->confirmCustomizationDetailsRateLimiter = $factory->create('MessagingApi-confirmCustomizationDetails');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-createAmazonMotors'), $this->rateLimitStorage);
            $this->createAmazonMotorsRateLimiter = $factory->create('MessagingApi-createAmazonMotors');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-createConfirmDeliveryDetails'), $this->rateLimitStorage);
            $this->createConfirmDeliveryDetailsRateLimiter = $factory->create('MessagingApi-createConfirmDeliveryDetails');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-createConfirmOrderDetails'), $this->rateLimitStorage);
            $this->createConfirmOrderDetailsRateLimiter = $factory->create('MessagingApi-createConfirmOrderDetails');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-createConfirmServiceDetails'), $this->rateLimitStorage);
            $this->createConfirmServiceDetailsRateLimiter = $factory->create('MessagingApi-createConfirmServiceDetails');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-createDigitalAccessKey'), $this->rateLimitStorage);
            $this->createDigitalAccessKeyRateLimiter = $factory->create('MessagingApi-createDigitalAccessKey');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-createLegalDisclosure'), $this->rateLimitStorage);
            $this->createLegalDisclosureRateLimiter = $factory->create('MessagingApi-createLegalDisclosure');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-createUnexpectedProblem'), $this->rateLimitStorage);
            $this->createUnexpectedProblemRateLimiter = $factory->create('MessagingApi-createUnexpectedProblem');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-createWarranty'), $this->rateLimitStorage);
            $this->createWarrantyRateLimiter = $factory->create('MessagingApi-createWarranty');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-getAttributes'), $this->rateLimitStorage);
            $this->getAttributesRateLimiter = $factory->create('MessagingApi-getAttributes');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-getMessagingActionsForOrder'), $this->rateLimitStorage);
            $this->getMessagingActionsForOrderRateLimiter = $factory->create('MessagingApi-getMessagingActionsForOrder');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('MessagingApi-sendInvoice'), $this->rateLimitStorage);
            $this->sendInvoiceRateLimiter = $factory->create('MessagingApi-sendInvoice');
        }

        $this->client = $client ?: new Client();
        $this->headerSelector = $selector ?: new HeaderSelector();
        $this->hostIndex = $hostIndex;
    }

    /**
     * Set the host index.
     *
     * @param int $hostIndex Host index (required)
     */
    public function setHostIndex(int $hostIndex): void
    {
        $this->hostIndex = $hostIndex;
    }

    /**
     * Get the host index.
     *
     * @return int Host index
     */
    public function getHostIndex(): int
    {
        return $this->hostIndex;
    }

    public function getConfig(): Configuration
    {
        return $this->config;
    }

    /**
     * Operation confirmCustomizationDetails.
     *
     * @param string                                   $amazon_order_id
     *                                                                      An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                                 $marketplace_ids
     *                                                                      A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmCustomizationDetailsRequest $body
     *                                                                      This contains the message body for a message. (required)
     * @param null|string                              $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function confirmCustomizationDetails(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmCustomizationDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): CreateConfirmCustomizationDetailsResponse {
        list($response) = $this->confirmCustomizationDetailsWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation confirmCustomizationDetailsWithHttpInfo.
     *
     * @param string                                   $amazon_order_id
     *                                                                      An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                                 $marketplace_ids
     *                                                                      A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmCustomizationDetailsRequest $body
     *                                                                      This contains the message body for a message. (required)
     * @param null|string                              $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateConfirmCustomizationDetailsResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function confirmCustomizationDetailsWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmCustomizationDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->confirmCustomizationDetailsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-confirmCustomizationDetails');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->confirmCustomizationDetailsRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateConfirmCustomizationDetailsResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateConfirmCustomizationDetailsResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateConfirmCustomizationDetailsResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateConfirmCustomizationDetailsResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation confirmCustomizationDetailsAsync.
     *
     * @param string                                   $amazon_order_id
     *                                                                  An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                                 $marketplace_ids
     *                                                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmCustomizationDetailsRequest $body
     *                                                                  This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function confirmCustomizationDetailsAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmCustomizationDetailsRequest $body
    ): PromiseInterface {
        return $this->confirmCustomizationDetailsAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation confirmCustomizationDetailsAsyncWithHttpInfo.
     *
     * @param string                                   $amazon_order_id
     *                                                                  An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                                 $marketplace_ids
     *                                                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmCustomizationDetailsRequest $body
     *                                                                  This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function confirmCustomizationDetailsAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmCustomizationDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateConfirmCustomizationDetailsResponse';
        $request = $this->confirmCustomizationDetailsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-confirmCustomizationDetails');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->confirmCustomizationDetailsRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'confirmCustomizationDetails'.
     *
     * @param string                                   $amazon_order_id
     *                                                                  An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                                 $marketplace_ids
     *                                                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmCustomizationDetailsRequest $body
     *                                                                  This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function confirmCustomizationDetailsRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmCustomizationDetailsRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling confirmCustomizationDetails'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling confirmCustomizationDetails'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.confirmCustomizationDetails, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling confirmCustomizationDetails'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/confirmCustomizationDetails';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createAmazonMotors.
     *
     * @param string                    $amazon_order_id
     *                                                       An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                  $marketplace_ids
     *                                                       A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateAmazonMotorsRequest $body
     *                                                       This contains the message body for a message. (required)
     * @param null|string               $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createAmazonMotors(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateAmazonMotorsRequest $body,
        ?string $restrictedDataToken = null
    ): CreateAmazonMotorsResponse {
        list($response) = $this->createAmazonMotorsWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createAmazonMotorsWithHttpInfo.
     *
     * @param string                    $amazon_order_id
     *                                                       An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                  $marketplace_ids
     *                                                       A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateAmazonMotorsRequest $body
     *                                                       This contains the message body for a message. (required)
     * @param null|string               $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateAmazonMotorsResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createAmazonMotorsWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateAmazonMotorsRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createAmazonMotorsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createAmazonMotors');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createAmazonMotorsRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateAmazonMotorsResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateAmazonMotorsResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateAmazonMotorsResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateAmazonMotorsResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createAmazonMotorsAsync.
     *
     * @param string                    $amazon_order_id
     *                                                   An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                  $marketplace_ids
     *                                                   A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateAmazonMotorsRequest $body
     *                                                   This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createAmazonMotorsAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateAmazonMotorsRequest $body
    ): PromiseInterface {
        return $this->createAmazonMotorsAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createAmazonMotorsAsyncWithHttpInfo.
     *
     * @param string                    $amazon_order_id
     *                                                   An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                  $marketplace_ids
     *                                                   A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateAmazonMotorsRequest $body
     *                                                   This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createAmazonMotorsAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateAmazonMotorsRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateAmazonMotorsResponse';
        $request = $this->createAmazonMotorsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createAmazonMotors');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createAmazonMotorsRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createAmazonMotors'.
     *
     * @param string                    $amazon_order_id
     *                                                   An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                  $marketplace_ids
     *                                                   A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateAmazonMotorsRequest $body
     *                                                   This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createAmazonMotorsRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateAmazonMotorsRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling createAmazonMotors'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling createAmazonMotors'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.createAmazonMotors, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createAmazonMotors'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/amazonMotors';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createConfirmDeliveryDetails.
     *
     * @param string                              $amazon_order_id
     *                                                                 An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                            $marketplace_ids
     *                                                                 A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmDeliveryDetailsRequest $body
     *                                                                 This contains the message body for a message. (required)
     * @param null|string                         $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createConfirmDeliveryDetails(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmDeliveryDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): CreateConfirmDeliveryDetailsResponse {
        list($response) = $this->createConfirmDeliveryDetailsWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createConfirmDeliveryDetailsWithHttpInfo.
     *
     * @param string                              $amazon_order_id
     *                                                                 An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                            $marketplace_ids
     *                                                                 A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmDeliveryDetailsRequest $body
     *                                                                 This contains the message body for a message. (required)
     * @param null|string                         $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateConfirmDeliveryDetailsResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createConfirmDeliveryDetailsWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmDeliveryDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createConfirmDeliveryDetailsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createConfirmDeliveryDetails');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createConfirmDeliveryDetailsRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateConfirmDeliveryDetailsResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateConfirmDeliveryDetailsResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateConfirmDeliveryDetailsResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateConfirmDeliveryDetailsResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createConfirmDeliveryDetailsAsync.
     *
     * @param string                              $amazon_order_id
     *                                                             An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                            $marketplace_ids
     *                                                             A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmDeliveryDetailsRequest $body
     *                                                             This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmDeliveryDetailsAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmDeliveryDetailsRequest $body
    ): PromiseInterface {
        return $this->createConfirmDeliveryDetailsAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createConfirmDeliveryDetailsAsyncWithHttpInfo.
     *
     * @param string                              $amazon_order_id
     *                                                             An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                            $marketplace_ids
     *                                                             A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmDeliveryDetailsRequest $body
     *                                                             This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmDeliveryDetailsAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmDeliveryDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateConfirmDeliveryDetailsResponse';
        $request = $this->createConfirmDeliveryDetailsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createConfirmDeliveryDetails');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createConfirmDeliveryDetailsRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createConfirmDeliveryDetails'.
     *
     * @param string                              $amazon_order_id
     *                                                             An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                            $marketplace_ids
     *                                                             A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmDeliveryDetailsRequest $body
     *                                                             This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmDeliveryDetailsRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmDeliveryDetailsRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling createConfirmDeliveryDetails'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling createConfirmDeliveryDetails'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.createConfirmDeliveryDetails, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createConfirmDeliveryDetails'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/confirmDeliveryDetails';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createConfirmOrderDetails.
     *
     * @param string                           $amazon_order_id
     *                                                              An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                         $marketplace_ids
     *                                                              A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmOrderDetailsRequest $body
     *                                                              This contains the message body for a message. (required)
     * @param null|string                      $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createConfirmOrderDetails(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmOrderDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): CreateConfirmOrderDetailsResponse {
        list($response) = $this->createConfirmOrderDetailsWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createConfirmOrderDetailsWithHttpInfo.
     *
     * @param string                           $amazon_order_id
     *                                                              An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                         $marketplace_ids
     *                                                              A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmOrderDetailsRequest $body
     *                                                              This contains the message body for a message. (required)
     * @param null|string                      $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateConfirmOrderDetailsResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createConfirmOrderDetailsWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmOrderDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createConfirmOrderDetailsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createConfirmOrderDetails');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createConfirmOrderDetailsRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateConfirmOrderDetailsResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateConfirmOrderDetailsResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateConfirmOrderDetailsResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateConfirmOrderDetailsResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createConfirmOrderDetailsAsync.
     *
     * @param string                           $amazon_order_id
     *                                                          An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                         $marketplace_ids
     *                                                          A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmOrderDetailsRequest $body
     *                                                          This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmOrderDetailsAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmOrderDetailsRequest $body
    ): PromiseInterface {
        return $this->createConfirmOrderDetailsAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createConfirmOrderDetailsAsyncWithHttpInfo.
     *
     * @param string                           $amazon_order_id
     *                                                          An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                         $marketplace_ids
     *                                                          A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmOrderDetailsRequest $body
     *                                                          This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmOrderDetailsAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmOrderDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateConfirmOrderDetailsResponse';
        $request = $this->createConfirmOrderDetailsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createConfirmOrderDetails');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createConfirmOrderDetailsRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createConfirmOrderDetails'.
     *
     * @param string                           $amazon_order_id
     *                                                          An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                         $marketplace_ids
     *                                                          A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmOrderDetailsRequest $body
     *                                                          This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmOrderDetailsRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmOrderDetailsRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling createConfirmOrderDetails'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling createConfirmOrderDetails'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.createConfirmOrderDetails, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createConfirmOrderDetails'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/confirmOrderDetails';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createConfirmServiceDetails.
     *
     * @param string                             $amazon_order_id
     *                                                                An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                           $marketplace_ids
     *                                                                A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmServiceDetailsRequest $body
     *                                                                This contains the message body for a message. (required)
     * @param null|string                        $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createConfirmServiceDetails(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmServiceDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): CreateConfirmServiceDetailsResponse {
        list($response) = $this->createConfirmServiceDetailsWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createConfirmServiceDetailsWithHttpInfo.
     *
     * @param string                             $amazon_order_id
     *                                                                An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                           $marketplace_ids
     *                                                                A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmServiceDetailsRequest $body
     *                                                                This contains the message body for a message. (required)
     * @param null|string                        $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateConfirmServiceDetailsResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createConfirmServiceDetailsWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmServiceDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createConfirmServiceDetailsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createConfirmServiceDetails');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createConfirmServiceDetailsRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateConfirmServiceDetailsResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateConfirmServiceDetailsResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateConfirmServiceDetailsResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateConfirmServiceDetailsResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createConfirmServiceDetailsAsync.
     *
     * @param string                             $amazon_order_id
     *                                                            An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                           $marketplace_ids
     *                                                            A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmServiceDetailsRequest $body
     *                                                            This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmServiceDetailsAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmServiceDetailsRequest $body
    ): PromiseInterface {
        return $this->createConfirmServiceDetailsAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createConfirmServiceDetailsAsyncWithHttpInfo.
     *
     * @param string                             $amazon_order_id
     *                                                            An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                           $marketplace_ids
     *                                                            A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmServiceDetailsRequest $body
     *                                                            This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmServiceDetailsAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmServiceDetailsRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateConfirmServiceDetailsResponse';
        $request = $this->createConfirmServiceDetailsRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createConfirmServiceDetails');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createConfirmServiceDetailsRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createConfirmServiceDetails'.
     *
     * @param string                             $amazon_order_id
     *                                                            An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                           $marketplace_ids
     *                                                            A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateConfirmServiceDetailsRequest $body
     *                                                            This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createConfirmServiceDetailsRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateConfirmServiceDetailsRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling createConfirmServiceDetails'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling createConfirmServiceDetails'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.createConfirmServiceDetails, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createConfirmServiceDetails'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/confirmServiceDetails';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createDigitalAccessKey.
     *
     * @param string                        $amazon_order_id
     *                                                           An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                      $marketplace_ids
     *                                                           A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateDigitalAccessKeyRequest $body
     *                                                           This contains the message body for a message. (required)
     * @param null|string                   $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createDigitalAccessKey(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateDigitalAccessKeyRequest $body,
        ?string $restrictedDataToken = null
    ): CreateDigitalAccessKeyResponse {
        list($response) = $this->createDigitalAccessKeyWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createDigitalAccessKeyWithHttpInfo.
     *
     * @param string                        $amazon_order_id
     *                                                           An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                      $marketplace_ids
     *                                                           A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateDigitalAccessKeyRequest $body
     *                                                           This contains the message body for a message. (required)
     * @param null|string                   $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateDigitalAccessKeyResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createDigitalAccessKeyWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateDigitalAccessKeyRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createDigitalAccessKeyRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createDigitalAccessKey');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createDigitalAccessKeyRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateDigitalAccessKeyResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateDigitalAccessKeyResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateDigitalAccessKeyResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateDigitalAccessKeyResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createDigitalAccessKeyAsync.
     *
     * @param string                        $amazon_order_id
     *                                                       An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                      $marketplace_ids
     *                                                       A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateDigitalAccessKeyRequest $body
     *                                                       This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createDigitalAccessKeyAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateDigitalAccessKeyRequest $body
    ): PromiseInterface {
        return $this->createDigitalAccessKeyAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createDigitalAccessKeyAsyncWithHttpInfo.
     *
     * @param string                        $amazon_order_id
     *                                                       An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                      $marketplace_ids
     *                                                       A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateDigitalAccessKeyRequest $body
     *                                                       This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createDigitalAccessKeyAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateDigitalAccessKeyRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateDigitalAccessKeyResponse';
        $request = $this->createDigitalAccessKeyRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createDigitalAccessKey');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createDigitalAccessKeyRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createDigitalAccessKey'.
     *
     * @param string                        $amazon_order_id
     *                                                       An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                      $marketplace_ids
     *                                                       A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateDigitalAccessKeyRequest $body
     *                                                       This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createDigitalAccessKeyRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateDigitalAccessKeyRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling createDigitalAccessKey'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling createDigitalAccessKey'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.createDigitalAccessKey, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createDigitalAccessKey'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/digitalAccessKey';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createLegalDisclosure.
     *
     * @param string                       $amazon_order_id
     *                                                          An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                     $marketplace_ids
     *                                                          A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateLegalDisclosureRequest $body
     *                                                          This contains the message body for a message. (required)
     * @param null|string                  $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createLegalDisclosure(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateLegalDisclosureRequest $body,
        ?string $restrictedDataToken = null
    ): CreateLegalDisclosureResponse {
        list($response) = $this->createLegalDisclosureWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createLegalDisclosureWithHttpInfo.
     *
     * @param string                       $amazon_order_id
     *                                                          An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                     $marketplace_ids
     *                                                          A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateLegalDisclosureRequest $body
     *                                                          This contains the message body for a message. (required)
     * @param null|string                  $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateLegalDisclosureResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createLegalDisclosureWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateLegalDisclosureRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createLegalDisclosureRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createLegalDisclosure');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createLegalDisclosureRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateLegalDisclosureResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateLegalDisclosureResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateLegalDisclosureResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateLegalDisclosureResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createLegalDisclosureAsync.
     *
     * @param string                       $amazon_order_id
     *                                                      An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                     $marketplace_ids
     *                                                      A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateLegalDisclosureRequest $body
     *                                                      This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createLegalDisclosureAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateLegalDisclosureRequest $body
    ): PromiseInterface {
        return $this->createLegalDisclosureAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createLegalDisclosureAsyncWithHttpInfo.
     *
     * @param string                       $amazon_order_id
     *                                                      An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                     $marketplace_ids
     *                                                      A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateLegalDisclosureRequest $body
     *                                                      This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createLegalDisclosureAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateLegalDisclosureRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateLegalDisclosureResponse';
        $request = $this->createLegalDisclosureRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createLegalDisclosure');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createLegalDisclosureRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createLegalDisclosure'.
     *
     * @param string                       $amazon_order_id
     *                                                      An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                     $marketplace_ids
     *                                                      A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateLegalDisclosureRequest $body
     *                                                      This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createLegalDisclosureRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateLegalDisclosureRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling createLegalDisclosure'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling createLegalDisclosure'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.createLegalDisclosure, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createLegalDisclosure'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/legalDisclosure';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createUnexpectedProblem.
     *
     * @param string                         $amazon_order_id
     *                                                            An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                       $marketplace_ids
     *                                                            A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateUnexpectedProblemRequest $body
     *                                                            This contains the message body for a message. (required)
     * @param null|string                    $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createUnexpectedProblem(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateUnexpectedProblemRequest $body,
        ?string $restrictedDataToken = null
    ): CreateUnexpectedProblemResponse {
        list($response) = $this->createUnexpectedProblemWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createUnexpectedProblemWithHttpInfo.
     *
     * @param string                         $amazon_order_id
     *                                                            An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                       $marketplace_ids
     *                                                            A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateUnexpectedProblemRequest $body
     *                                                            This contains the message body for a message. (required)
     * @param null|string                    $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateUnexpectedProblemResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createUnexpectedProblemWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateUnexpectedProblemRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createUnexpectedProblemRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createUnexpectedProblem');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createUnexpectedProblemRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateUnexpectedProblemResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateUnexpectedProblemResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateUnexpectedProblemResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateUnexpectedProblemResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createUnexpectedProblemAsync.
     *
     * @param string                         $amazon_order_id
     *                                                        An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                       $marketplace_ids
     *                                                        A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateUnexpectedProblemRequest $body
     *                                                        This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createUnexpectedProblemAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateUnexpectedProblemRequest $body
    ): PromiseInterface {
        return $this->createUnexpectedProblemAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createUnexpectedProblemAsyncWithHttpInfo.
     *
     * @param string                         $amazon_order_id
     *                                                        An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                       $marketplace_ids
     *                                                        A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateUnexpectedProblemRequest $body
     *                                                        This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createUnexpectedProblemAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateUnexpectedProblemRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateUnexpectedProblemResponse';
        $request = $this->createUnexpectedProblemRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createUnexpectedProblem');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createUnexpectedProblemRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createUnexpectedProblem'.
     *
     * @param string                         $amazon_order_id
     *                                                        An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]                       $marketplace_ids
     *                                                        A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateUnexpectedProblemRequest $body
     *                                                        This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createUnexpectedProblemRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateUnexpectedProblemRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling createUnexpectedProblem'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling createUnexpectedProblem'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.createUnexpectedProblem, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createUnexpectedProblem'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/unexpectedProblem';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createWarranty.
     *
     * @param string                $amazon_order_id
     *                                                   An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]              $marketplace_ids
     *                                                   A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateWarrantyRequest $body
     *                                                   This contains the message body for a message. (required)
     * @param null|string           $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createWarranty(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateWarrantyRequest $body,
        ?string $restrictedDataToken = null
    ): CreateWarrantyResponse {
        list($response) = $this->createWarrantyWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createWarrantyWithHttpInfo.
     *
     * @param string                $amazon_order_id
     *                                                   An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]              $marketplace_ids
     *                                                   A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateWarrantyRequest $body
     *                                                   This contains the message body for a message. (required)
     * @param null|string           $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\CreateWarrantyResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createWarrantyWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateWarrantyRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createWarrantyRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createWarranty');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createWarrantyRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\CreateWarrantyResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\CreateWarrantyResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\CreateWarrantyResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\CreateWarrantyResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createWarrantyAsync.
     *
     * @param string                $amazon_order_id
     *                                               An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]              $marketplace_ids
     *                                               A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateWarrantyRequest $body
     *                                               This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createWarrantyAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateWarrantyRequest $body
    ): PromiseInterface {
        return $this->createWarrantyAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createWarrantyAsyncWithHttpInfo.
     *
     * @param string                $amazon_order_id
     *                                               An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]              $marketplace_ids
     *                                               A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateWarrantyRequest $body
     *                                               This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createWarrantyAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateWarrantyRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\CreateWarrantyResponse';
        $request = $this->createWarrantyRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-createWarranty');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createWarrantyRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createWarranty'.
     *
     * @param string                $amazon_order_id
     *                                               An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]              $marketplace_ids
     *                                               A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param CreateWarrantyRequest $body
     *                                               This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createWarrantyRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        CreateWarrantyRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling createWarranty'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling createWarranty'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.createWarranty, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createWarranty'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/warranty';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getAttributes.
     *
     * @param string      $amazon_order_id
     *                                         An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]    $marketplace_ids
     *                                         A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param null|string $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function getAttributes(
        string $amazon_order_id,
        array $marketplace_ids,
        ?string $restrictedDataToken = null
    ): GetAttributesResponse {
        list($response) = $this->getAttributesWithHttpInfo($amazon_order_id, $marketplace_ids, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation getAttributesWithHttpInfo.
     *
     * @param string      $amazon_order_id
     *                                         An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]    $marketplace_ids
     *                                         A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param null|string $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\GetAttributesResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function getAttributesWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->getAttributesRequest($amazon_order_id, $marketplace_ids);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-getAttributes');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->getAttributesRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\GetAttributesResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\GetAttributesResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\GetAttributesResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\GetAttributesResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation getAttributesAsync.
     *
     * @param string   $amazon_order_id
     *                                  An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[] $marketplace_ids
     *                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getAttributesAsync(
        string $amazon_order_id,
        array $marketplace_ids
    ): PromiseInterface {
        return $this->getAttributesAsyncWithHttpInfo($amazon_order_id, $marketplace_ids)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation getAttributesAsyncWithHttpInfo.
     *
     * @param string   $amazon_order_id
     *                                  An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[] $marketplace_ids
     *                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getAttributesAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\GetAttributesResponse';
        $request = $this->getAttributesRequest($amazon_order_id, $marketplace_ids);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-getAttributes');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->getAttributesRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'getAttributes'.
     *
     * @param string   $amazon_order_id
     *                                  An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[] $marketplace_ids
     *                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getAttributesRequest(
        string $amazon_order_id,
        array $marketplace_ids
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling getAttributes'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling getAttributes'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.getAttributes, number of items must be less than or equal to 1.');
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/attributes';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            '',
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'GET',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getMessagingActionsForOrder.
     *
     * @param string      $amazon_order_id
     *                                         An Amazon order identifier. This specifies the order for which you want a list of available message types. (required)
     * @param string[]    $marketplace_ids
     *                                         A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param null|string $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function getMessagingActionsForOrder(
        string $amazon_order_id,
        array $marketplace_ids,
        ?string $restrictedDataToken = null
    ): GetMessagingActionsForOrderResponse {
        list($response) = $this->getMessagingActionsForOrderWithHttpInfo($amazon_order_id, $marketplace_ids, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation getMessagingActionsForOrderWithHttpInfo.
     *
     * @param string      $amazon_order_id
     *                                         An Amazon order identifier. This specifies the order for which you want a list of available message types. (required)
     * @param string[]    $marketplace_ids
     *                                         A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param null|string $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\GetMessagingActionsForOrderResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function getMessagingActionsForOrderWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->getMessagingActionsForOrderRequest($amazon_order_id, $marketplace_ids);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-getMessagingActionsForOrder');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->getMessagingActionsForOrderRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\GetMessagingActionsForOrderResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\GetMessagingActionsForOrderResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\GetMessagingActionsForOrderResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\GetMessagingActionsForOrderResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation getMessagingActionsForOrderAsync.
     *
     * @param string   $amazon_order_id
     *                                  An Amazon order identifier. This specifies the order for which you want a list of available message types. (required)
     * @param string[] $marketplace_ids
     *                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getMessagingActionsForOrderAsync(
        string $amazon_order_id,
        array $marketplace_ids
    ): PromiseInterface {
        return $this->getMessagingActionsForOrderAsyncWithHttpInfo($amazon_order_id, $marketplace_ids)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation getMessagingActionsForOrderAsyncWithHttpInfo.
     *
     * @param string   $amazon_order_id
     *                                  An Amazon order identifier. This specifies the order for which you want a list of available message types. (required)
     * @param string[] $marketplace_ids
     *                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getMessagingActionsForOrderAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\GetMessagingActionsForOrderResponse';
        $request = $this->getMessagingActionsForOrderRequest($amazon_order_id, $marketplace_ids);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-getMessagingActionsForOrder');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->getMessagingActionsForOrderRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'getMessagingActionsForOrder'.
     *
     * @param string   $amazon_order_id
     *                                  An Amazon order identifier. This specifies the order for which you want a list of available message types. (required)
     * @param string[] $marketplace_ids
     *                                  A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getMessagingActionsForOrderRequest(
        string $amazon_order_id,
        array $marketplace_ids
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling getMessagingActionsForOrder'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling getMessagingActionsForOrder'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.getMessagingActionsForOrder, number of items must be less than or equal to 1.');
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            '',
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'GET',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation sendInvoice.
     *
     * @param string         $amazon_order_id
     *                                            An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]       $marketplace_ids
     *                                            A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param InvoiceRequest $body
     *                                            This contains the message body for a message. (required)
     * @param null|string    $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function sendInvoice(
        string $amazon_order_id,
        array $marketplace_ids,
        InvoiceRequest $body,
        ?string $restrictedDataToken = null
    ): InvoiceResponse {
        list($response) = $this->sendInvoiceWithHttpInfo($amazon_order_id, $marketplace_ids, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation sendInvoiceWithHttpInfo.
     *
     * @param string         $amazon_order_id
     *                                            An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]       $marketplace_ids
     *                                            A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param InvoiceRequest $body
     *                                            This contains the message body for a message. (required)
     * @param null|string    $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\messaging\v1\InvoiceResponse, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function sendInvoiceWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        InvoiceRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->sendInvoiceRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-sendInvoice');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->sendInvoiceRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\messaging\v1\InvoiceResponse' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\messaging\v1\InvoiceResponse' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\messaging\v1\InvoiceResponse', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\messaging\v1\InvoiceResponse',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation sendInvoiceAsync.
     *
     * @param string         $amazon_order_id
     *                                        An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]       $marketplace_ids
     *                                        A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param InvoiceRequest $body
     *                                        This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function sendInvoiceAsync(
        string $amazon_order_id,
        array $marketplace_ids,
        InvoiceRequest $body
    ): PromiseInterface {
        return $this->sendInvoiceAsyncWithHttpInfo($amazon_order_id, $marketplace_ids, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation sendInvoiceAsyncWithHttpInfo.
     *
     * @param string         $amazon_order_id
     *                                        An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]       $marketplace_ids
     *                                        A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param InvoiceRequest $body
     *                                        This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function sendInvoiceAsyncWithHttpInfo(
        string $amazon_order_id,
        array $marketplace_ids,
        InvoiceRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\messaging\v1\InvoiceResponse';
        $request = $this->sendInvoiceRequest($amazon_order_id, $marketplace_ids, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'MessagingApi-sendInvoice');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->sendInvoiceRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'sendInvoice'.
     *
     * @param string         $amazon_order_id
     *                                        An Amazon order identifier. This identifies the order for which a message is sent. (required)
     * @param string[]       $marketplace_ids
     *                                        A marketplace identifier. This identifies the marketplace in which the order was placed. You can only specify one marketplace. (required)
     * @param InvoiceRequest $body
     *                                        This contains the message body for a message. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function sendInvoiceRequest(
        string $amazon_order_id,
        array $marketplace_ids,
        InvoiceRequest $body
    ): Request {
        // verify the required parameter 'amazon_order_id' is set
        if (null === $amazon_order_id || (is_array($amazon_order_id) && 0 === count($amazon_order_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_order_id when calling sendInvoice'
            );
        }
        // verify the required parameter 'marketplace_ids' is set
        if (null === $marketplace_ids || (is_array($marketplace_ids) && 0 === count($marketplace_ids))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $marketplace_ids when calling sendInvoice'
            );
        }
        if (count($marketplace_ids) > 1) {
            throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling MessagingApi.sendInvoice, number of items must be less than or equal to 1.');
        }

        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling sendInvoice'
            );
        }

        $resourcePath = '/messaging/v1/orders/{amazonOrderId}/messages/invoice';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $marketplace_ids,
            'marketplaceIds', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);

        // path params
        if (null !== $amazon_order_id) {
            $resourcePath = str_replace(
                '{amazonOrderId}',
                ObjectSerializer::toPathValue($amazon_order_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/hal+json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option.
     *
     * @return array of http client options
     *
     * @throws \RuntimeException on file opening failure
     */
    protected function createHttpClientOption(): array
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: '.$this->config->getDebugFile());
            }
        }

        return $options;
    }
}
